/*
 * @Author: your Name
 * @Date: 2022-07-13 14:52:01
 * @LastEditors: your Name
 * @LastEditTime: 2022-07-13 15:01:51
 * @Description: 
 */

let obj = {
  name: "why",
  age: 18,
  friend: {
    name: "james",
    address: {
      city: "广州"
    }
  },
   // 数组类型
   hobbies: ["abc", "cba", "nba"],
}

function deepClone(originValue) {
  let newObj = Array.isArray(originValue) ? [] : {}
  // // 判断传入的originValue是否是一个对象类型
  if(typeof originValue !== 'object') {
    return originValue
  }
  

  for(let k in originValue) {
    newObj[k] = deepClone(originValue[k])
  }
  return newObj
}

let newObj = deepClone(obj)
obj.friend.name = 'code'
console.log(newObj)